<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<h:head></h:head>
<body>
	<f:view>
		<h:form prependId="false">

			<p:fieldset legend="Lista de Usuários" toggleable="false" toggleSpeed="500" style="width:600px; margin-left:10%">

				<p:dataTable value="#{usuarioFacesBean.all}" var="user" paginator="true" rows="5"
					paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15">
					<p:column>
						<f:facet name="header">
							<h:outputText value="Nome" />
						</f:facet>
						<h:outputText value="#{user.nome}" />
					</p:column>

					<p:column>
						<f:facet name="header">
							<h:outputText value="Endereço" />
						</f:facet>
						<h:outputText value="#{user.endereco}" />
					</p:column>

					<p:column>
						<f:facet name="header">
							<h:outputText value="Alterar" />
						</f:facet>
						<h:commandLink action="#{usuarioFacesBean.redirecionarPaginaAlterar}">
							<f:setPropertyActionListener target="#{usuarioFacesBean.usuario}" value="#{user}" />
							<h:graphicImage value="/images/icone_editar.png" />
						</h:commandLink>
					</p:column>

					<p:column>
						<f:facet name="header">
							<h:outputText value="Excluir" />
						</f:facet>

						<p:commandLink onclick="confirmation#{user.id}.show()">
							<h:graphicImage value="/images/icone_excluir.png" />
						</p:commandLink>

						<p:confirmDialog message="Deseja realmente excluir este registro?" header="Excluir registro" severity="alert" widgetVar="confirmation#{user.id}">

							<p:commandButton action="#{usuarioFacesBean.excluirPessoa}" value="Sim">
								<f:setPropertyActionListener target="#{usuarioFacesBean.usuario}" value="#{user}" />
							</p:commandButton>

							<p:commandButton value="Não" onclick="confirmation#{user.id}.hide()" type="button" />
						</p:confirmDialog>
					</p:column>

				</p:dataTable>
				<br />
				<p:commandButton value="Cadastrar" action="#{usuarioFacesBean.redirecionarCadastroUsuario}" />

			</p:fieldset>
		</h:form>
	</f:view>

</body>
</html>
